<template>
	<view class="content">
		<!-- 下载App -->
		<view class="mask"></view>
		<view class="download u-flex u-row-between">
			<view class="u-flex">
				<view class="logo">
					<image class="logo-img" src="/static/logo.png" mode=""></image>
				</view>
				<view class="download-content">
					<view class="">中拍汇</view>
					<view>文玩在线直播拍卖</view>
				</view>
			</view>
			<view class="download-btn" @click="openApp()">
				<text>打开APP</text>
				<!-- <a href="zhongpaihui://">打开APP</a> -->
			</view>
		</view>
		

		<view class="box1" style="margin-top: 180rpx;">
			<image class="bg" src="/static/images/store-bg.jpg" mode="aspectFill"></image>
			<view class="items1 u-flex u-row-between">
				<image class="head" :src="storeInfo.logo" mode="aspectFill"></image>
				<view class="text">
					<view class="tit">{{storeInfo.title}}</view>
					<view class="info u-flex">
						<image class="icon" src="/static/images/store-jx1.png" mode="aspectFill"></image>
						<text>精选店铺</text>
					</view>
				</view>
				<view class="btns u-flex u-row-between">
					<u-icon name="heart" color="#ffffff" size="46"></u-icon>
					<image class="btn-item chat" src="/static/images/store-chat1.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="items2 u-flex u-row-between">
				<view class="col">
					<view class="number u-flex u-row-center u-col-bottom">
						<view class="unit">¥</view>
						<text class="u-m-l-10">{{storeInfo.xiaobao_price}}</text>
					</view>
					<view class="tit">消保金</view>
				</view>
				<view class="col">
					<view class="number u-flex u-row-center u-col-bottom">
						<text>{{storeInfo.pingjia_nums}}</text>
					</view>
					<view class="tit">店铺评价</view>
				</view>
				<view class="col">
					<view class="number u-flex u-row-center u-col-bottom">
						<text>{{storeInfo.fans_nums}}</text>
					</view>
					<view class="tit">粉丝数</view>
				</view>
			</view>
		</view>

		<view class="box2 u-flex u-row-between" v-if="storeInfo.zhibo && storeInfo.zhibo.id">
			<image class="pic" :src="storeInfo.zhibo.litpic" mode="aspectFill"></image>
			<view class="text">
				<view class="tit u-line-1" style="width: 240rpx;">{{storeInfo.zhibo.title}}</view>
				<view class="info u-flex">
					<view class="info-in u-flex">
						<text class="tg">直播中</text>
						<text>{{storeInfo.hits}} 观看</text>
					</view>
				</view>
			</view>
			<view class="btns">去观看</view>
		</view>

		<view class="box3">
			<view class="tab">
				<u-tabs :list="tabList" :current="tabCurrent" @change="tabChange" font-size="28"
					inactive-color="#999999" active-color="#333333" :bar-style="{background: '#B20000'}"></u-tabs>
			</view>
		</view>

		<view class="goods" v-if="list.length">
			<u-row gutter="0" justify="space-between">
				<u-col span="5.7" v-for="item in list">
					<view class="goods-items">
						<image :src="item.imgs.split(',')[0]" mode="aspectFill"></image>
						<view class="goods-items-footer">
							<view class="goods-items-footer-title u-line-2">{{item.title}}</view>
							<view class="goods-items-price u-flex u-row-between">
								<text>￥{{item.price}}</text>
								<text v-if="item.type==1">出价{{item.chujia_nums}}次</text>
								<text v-if="item.type==2">已售{{item.yishou_nums}}件</text>
							</view>
						</view>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="more u-p-t-20 u-p-b-40" v-if="list.length && total > 10">
			<u-loadmore :status="status" />
		</view>
		
		<view class="u-p-t-80" v-if="!list.length">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>

		<view class="u-p-b-30"></view>

	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				tabList: [{
					name: '全部拍品'
				}, {
					name: '一口价'
				}],
				tabCurrent: 0,
				sxTabList: [
					{
						name: '价格'
					}, {
						name: '即将截拍'
					}
				],
				sxTabCurrent: 0,
				// 店铺ID
				id: null,
				// 店铺信息
				storeInfo: {},
				queryParms: {
					page: 0,
					size: 10,
					tid: 0,
					type: 1,
					sid: null
				},
				status: 'loadmore',
				list: [],
				total: 1,
			}
		},
		onLoad(option) {
			if (option.id) {
				this.id = option.id;
				this.queryParms.sid = option.id;
			}
		},
		onShow() {
			if(this.id) {
				this.getDetails();
				this.getList();
			}
		},
		methods: {
			// 打开APP
			openApp() {
				console.log('打开App')
				const isIOS = uni.getSystemInfoSync().platform === 'ios';
				const url = isIOS ? 'zhongpaihui://' : 'zhongpaihui://?url=/pages/mine/seller/store&id='+this.id;
				// 使用 try-catch 来处理可能的错误
				try {
					console.log(url)
					window.location.href = url;
				} catch (e) {
					// 跳转失败，可能是因为没有安装App
					console.log('App未安装');
					alert('未找到应用，请前往应用市场下载')
					// 可以在这里引导用户前往App Store或者其他备用页面
				}
				// window.location.href = 'zhongpaihui:///pages/mine/seller/store?id='+this.id;
			},
			// 获取店铺详情
			getDetails() {
				this.$u.post('/company/read', {
					uid: this.id
				}).then(res => {
					console.log('店铺详情', res)
					if (res.code == 0 || res.code == 201) {
						this.$u.toast(res.message);
						return false;
					}
					this.storeInfo = res;
				});
			},
			// 获取店铺商品数据
			getList() {
				if (this.list.length >= this.total) return;
				this.status = 'loading';
				this.queryParms.page++;
				this.$u.post('/paipin/index', this.queryParms).then(res => {
					this.total = res.total;
					this.list = [...this.list, ...res.data];
					if (this.list.length >= this.total) {
						this.status = 'nomore';
					} else {
						this.status = 'loading';
					}
				}).catch(() => {
					this.status = 'nomore';
				});
			},
			tabChange(index) {
				this.tabCurrent = index;
				if(index==0) {
					this.queryParms.type = 1;
				} else {
					this.queryParms.type = 2;
				}
				this.total = 1;
				this.list = [];
				this.queryParms.page = 0;
				this.getList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.box1 {
		margin: 38rpx 36rpx;
		padding: 30rpx;
		height: 264rpx;
		border-radius: 24rpx;
		position: relative;
		z-index: 1;
		overflow: hidden;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100% !important;
			height: 100% !important;
			z-index: -1;
		}

		.items1 {
			padding-right: 30rpx;
			margin-bottom: 24rpx;

			.head {
				margin-right: 12rpx;
				width: 90rpx !important;
				height: 90rpx !important;
				border-radius: 50%;
				border: 4rpx solid #fff;
				flex-shrink: 0;
			}

			.text {
				flex-grow: 1;
			}

			.tit {
				font-size: 32rpx;
				color: #FFFFFF;
				font-weight: bold;
				line-height: 44rpx;
			}

			.info {
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 42rpx;

				.icon {
					margin-right: 6rpx;
					width: 16rpx !important;
					height: 26rpx !important;
					flex-shrink: 0;
				}
			}

			.btns {
				.btn-item {
					margin-left: 50rpx;
					flex-shrink: 0;
				}

				.heart {
					width: 48rpx;
					height: 42rpx;
				}

				.chat {
					width: 42rpx;
					height: 40rpx;
				}
			}
		}

		.items2 {
			text-align: center;

			.col {
				position: relative;
				flex-grow: 1;
			}

			.col::before {
				content: '';
				position: absolute;
				right: 0;
				top: 50%;
				width: 1px;
				height: 32rpx;
				background-color: #fff;
				opacity: .2;
				transform: translateY(-50%);
			}

			.col:last-child::before {
				display: none;
			}

			.number {
				font-size: 40rpx;
				color: #FFFFFF;
				line-height: 56rpx;

				.unit {
					font-size: 28rpx;
					line-height: 46rpx;
				}
			}

			.tit {
				font-size: 24rpx;
				color: #FFFFFF;
				height: 68rpx;
			}
		}
	}

	.box2 {
		margin: 38rpx 36rpx;
		padding: 26rpx 46rpx;
		background-color: #FFFFFF;
		box-shadow: 0 16rpx 30rpx rgba(0, 0, 0, 0.02);
		border-radius: 24rpx;

		.pic {
			width: 112rpx !important;
			height: 112rpx !important;
			border-radius: 12rpx;
			overflow: hidden;
			flex-shrink: 0;
		}

		.text {
			padding: 0 32rpx;
			flex-grow: 1;
		}

		.tit {
			font-size: 28rpx;
			color: #333333;
			font-weight: bold;
			line-height: 40rpx;
		}

		.info {
			margin-top: 14rpx;
			font-size: 20rpx;
			color: #C3C3C3;
			line-height: 34rpx;

			.info-in {
				padding-right: 10rpx;
				border-radius: 8rpx;
				background-color: #F9F9F9;
				overflow: hidden;
			}

			.tg {
				margin-right: 14rpx;
				padding: 0 8rpx;
				font-size: 20rpx;
				color: #FFFFFF;
				line-height: 34rpx;
				background-color: #BC1C10;
			}
		}

		.btns {
			width: 168rpx;
			height: 64rpx;
			line-height: 64rpx;
			font-size: 24rpx;
			color: #FFFFFF;
			text-align: center;
			background-color: #B20000;
			border-radius: 210rpx;
			flex-shrink: 0;
		}
	}

	.box3 {
		margin: 30rpx 36rpx;
		background-color: #fff;
		box-shadow: 0 16rpx 30rpx rgba(0, 0, 0, 0.02);
		border-radius: 24rpx;
		overflow: hidden;
	}

	.tab {
		height: 96rpx;
		background-color: #fff;

		::v-deep .u-scroll-box {
			display: -webkit-flex;
			display: flex;
		}

		::v-deep .u-tab-item {
			height: 96rpx !important;
			line-height: 96rpx !important;
			overflow: visible !important;
			display: block !important;
			flex-grow: 1 !important;
			position: relative;
		}

		::v-deep .u-tab-item::before {
			content: '';
			position: absolute;
			right: 0;
			top: 50%;
			width: 4rpx;
			height: 44rpx;
			background-color: #F9F9F9;
			transform: translateY(-50%);
		}

		::v-deep .u-tab-item:last-child::before {
			display: none;
		}

		::v-deep .u-tab-bar {
			bottom: -3px;
		}
	}

	.tab2 {
		border-top: 2rpx solid #F3F3F3;
		height: 96rpx;
		text-align: center;
		background-color: #fff;
		box-shadow: 0px 16 30px 0px rgba(0, 0, 0, 0.02);

		.tab-item {
			padding: 0 20rpx;
			height: 96rpx;
			position: relative;
			flex: 1;
		}

		.tab-item::before {
			content: '';
			position: absolute;
			right: 0;
			top: 50%;
			width: 4rpx;
			height: 44rpx;
			background-color: #F9F9F9;
			transform: translateY(-50%);
		}

		.tab-item:last-child::before {
			display: none;
		}

		.tit {
			font-size: 24rpx;
			color: #999999;
			line-height: 48rpx;
		}

		.icon {
			margin-left: 10rpx;
			display: block;
			width: 18rpx !important;
			height: 24rpx !important;
			flex-shrink: 0;
		}

		.active {
			.tit {
				color: #333333;
			}
		}
	}

	.goods {
		margin: 20rpx 40rpx;

		.goods-items {
			width: 100%;
			border-radius: 21rpx;
			overflow: hidden;
			margin: 12rpx 0;

			image {
				display: block;
				width: 100% !important;
				height: 366rpx !important;
			}

			.goods-items-footer {
				background-color: #fff;
				padding: 10rpx 20rpx 20rpx;
				font-size: 24rpx;
				
				.goods-items-footer-title {
					height: 68rpx;
				}

				.goods-items-price {
					margin-top: 10rpx;
					display: flex;
					align-items: center;

					text:nth-of-type(1) {
						color: #BC1C10;
						font-size: 28rpx;
					}

					text:nth-of-type(2) {
						color: #6C6C6C;
						font-size: 24rpx;
						margin-left: 20rpx;
					}
				}
			}
		}
	}
	
	.mask {
		position: fixed;
		width: 100%;
		height: 100vh;
		top: 0;
		left: 0;
		z-index: 999;
		background-color: rgba(0, 0, 0, .2);
	}
	
	.download {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		background-color: #fff;
		// border-bottom: 3px solid red;
		box-shadow: 0 0 4rpx 2rpx #f7f7f7;
		padding: 30rpx 20rpx;
	
		.logo {
			width: 100rpx;
			height: 100rpx;
			margin-right: 20rpx;
	
			.logo-img {
				display: block;
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
			}
		}
	
		.download-content {
			height: 90rpx;
			display: flex;
			flex-flow: column;
			justify-content: space-between;
	
			view:nth-of-type(1) {
				font-weight: bold;
				font-size: 32rpx;
			}
		}
	
		.download-btn {
			a, text {
				display: block;
				padding: 18rpx 28rpx;
				background-color: #AA1E14;
				color: #fff;
				font-size: 28rpx;
				border-radius: 50rpx;
				text-decoration: none;
			}
		}
	}
</style>